From e0dd5c3b38b04af82418279baeefd3d00f00d12a Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 20 Jun 2008 15:21:26 +0100 Subject: [PATCH] Clean up domain_create() interface. Signed-off-by: Keir Fraser --- xen/arch/ia64/xen/mm.c | 6 ++-- xen/arch/x86/mm.c | 4 +-- xen/common/domain.c | 63 ++++++++++++++++++++-------------------- xen/include/xen/domain.h | 3 -- xen/include/xen/sched.h | 12 +++++--- 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/xen/arch/ia64/xen/mm.c b/xen/arch/ia64/xen/mm.c index 0a4994ba8b..385cac3189 100644 --- a/xen/arch/ia64/xen/mm.c +++ b/xen/arch/ia64/xen/mm.c @@ -207,7 +207,7 @@ alloc_dom_xen_and_dom_io(void) * Any Xen-heap pages that we will allow to be mapped will have * their domain field set to dom_xen. */ - dom_xen = alloc_domain(DOMID_XEN); + dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0); BUG_ON(dom_xen == NULL); /* @@ -215,7 +215,7 @@ alloc_dom_xen_and_dom_io(void) * This domain owns I/O pages that are within the range of the page_info * array. Mappings occur at the priv of the caller. */ - dom_io = alloc_domain(DOMID_IO); + dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0); BUG_ON(dom_io == NULL); } @@ -1553,7 +1553,7 @@ expose_p2m_init(void) * Initialise our DOMID_P2M domain. * This domain owns m2p table pages. */ - dom_p2m = alloc_domain(DOMID_P2M); + dom_p2m = domain_create(DOMID_P2M, DOMCRF_dummy, 0); BUG_ON(dom_p2m == NULL); dom_p2m->max_pages = ~0U; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 305fbdce74..54b42efb65 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -219,7 +219,7 @@ void __init arch_init_memory(void) * Any Xen-heap pages that we will allow to be mapped will have * their domain field set to dom_xen. */ - dom_xen = alloc_domain(DOMID_XEN); + dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0); BUG_ON(dom_xen == NULL); /* @@ -227,7 +227,7 @@ void __init arch_init_memory(void) * This domain owns I/O pages that are within the range of the page_info * array. Mappings occur at the priv of the caller. */ - dom_io = alloc_domain(DOMID_IO); + dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0); BUG_ON(dom_io == NULL); /* First 1MB of RAM is historically marked as I/O. */ diff --git a/xen/common/domain.c b/xen/common/domain.c index 2965553ed6..c5779ca0ff 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -73,36 +73,13 @@ int current_domain_id(void) return current->domain->domain_id; } -struct domain *alloc_domain(domid_t domid) +static struct domain *alloc_domain_struct(void) { - struct domain *d; - - if ( (d = xmalloc(struct domain)) == NULL ) - return NULL; - - memset(d, 0, sizeof(*d)); - d->domain_id = domid; - - if ( xsm_alloc_security_domain(d) != 0 ) - { - free_domain(d); - return NULL; - } - - atomic_set(&d->refcnt, 1); - spin_lock_init(&d->domain_lock); - spin_lock_init(&d->page_alloc_lock); - spin_lock_init(&d->shutdown_lock); - spin_lock_init(&d->hypercall_deadlock_mutex); - INIT_LIST_HEAD(&d->page_list); - INIT_LIST_HEAD(&d->xenpage_list); - - return d; + return xmalloc(struct domain); } -void free_domain(struct domain *d) +static void free_domain_struct(struct domain *d) { - xsm_free_security_domain(d); xfree(d); } @@ -210,19 +187,39 @@ struct domain *domain_create( domid_t domid, unsigned int domcr_flags, ssidref_t ssidref) { struct domain *d, **pd; - enum { INIT_evtchn = 1, INIT_gnttab = 2, INIT_arch = 8 }; + enum { INIT_xsm = 1u<<0, INIT_rangeset = 1u<<1, INIT_evtchn = 1u<<2, + INIT_gnttab = 1u<<3, INIT_arch = 1u<<4 }; int init_status = 0; - if ( (d = alloc_domain(domid)) == NULL ) + if ( (d = alloc_domain_struct()) == NULL ) return NULL; + memset(d, 0, sizeof(*d)); + d->domain_id = domid; + + if ( xsm_alloc_security_domain(d) != 0 ) + goto fail; + init_status |= INIT_xsm; + + atomic_set(&d->refcnt, 1); + spin_lock_init(&d->domain_lock); + spin_lock_init(&d->page_alloc_lock); + spin_lock_init(&d->shutdown_lock); + spin_lock_init(&d->hypercall_deadlock_mutex); + INIT_LIST_HEAD(&d->page_list); + INIT_LIST_HEAD(&d->xenpage_list); + if ( domcr_flags & DOMCRF_hvm ) d->is_hvm = 1; if ( (domid == 0) && opt_dom0_vcpus_pin ) d->is_pinned = 1; + if ( domcr_flags & DOMCRF_dummy ) + return d; + rangeset_domain_initialise(d); + init_status |= INIT_rangeset; if ( !is_idle_domain(d) ) { @@ -278,8 +275,11 @@ struct domain *domain_create( grant_table_destroy(d); if ( init_status & INIT_evtchn ) evtchn_destroy(d); - rangeset_domain_destroy(d); - free_domain(d); + if ( init_status & INIT_rangeset ) + rangeset_domain_destroy(d); + if ( init_status & INIT_xsm ) + xsm_free_security_domain(d); + free_domain_struct(d); return NULL; } @@ -535,7 +535,8 @@ static void complete_domain_destroy(struct rcu_head *head) if ( d->target != NULL ) put_domain(d->target); - free_domain(d); + xsm_free_security_domain(d); + free_domain_struct(d); send_guest_global_virq(dom0, VIRQ_DOM_EXC); } diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 8483d42f9e..cf82d07ea0 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -16,9 +16,6 @@ int boot_vcpu( struct vcpu *alloc_idle_vcpu(unsigned int cpu_id); void vcpu_reset(struct vcpu *v); -struct domain *alloc_domain(domid_t domid); -void free_domain(struct domain *d); - struct xen_domctl_getdomaininfo; void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 937ebb295e..1565e65978 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -315,10 +315,14 @@ static inline struct domain *get_current_domain(void) struct domain *domain_create( domid_t domid, unsigned int domcr_flags, ssidref_t ssidref); /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */ -#define _DOMCRF_hvm 0 -#define DOMCRF_hvm (1U<<_DOMCRF_hvm) -#define _DOMCRF_hap 1 -#define DOMCRF_hap (1U<<_DOMCRF_hap) +#define _DOMCRF_hvm 0 +#define DOMCRF_hvm (1U<<_DOMCRF_hvm) + /* DOMCRF_hap: Create a domain with hardware-assisted paging. */ +#define _DOMCRF_hap 1 +#define DOMCRF_hap (1U<<_DOMCRF_hap) + /* DOMCRF_dummy: Create a dummy domain (not scheduled; not on domain list) */ +#define _DOMCRF_dummy 2 +#define DOMCRF_dummy (1U<<_DOMCRF_dummy) int construct_dom0( struct domain *d, -- 2.30.2